Home:ALL Converter>What is [ and ] in c#?

What is [ and ] in c#?

Ask Time:2010-08-24T21:43:22         Author:001

Json Formatter

What is the [ and ] in c#? what is it used for? what does it mean?

example

[DefaultValue(null)]
[JsonName("name")]
public string Name
{
    get
    {
        if (this.name == null)
        {
            return String.Empty;
        }
        return this.name;
    }
}

Author:001,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/3557074/what-is-and-in-c
Manu :

Those are used for attributes in C#, are in a way like java annotations. Attributes are used by reflection. Attributes are used to give metainformation.\nYou can check the following links:\nhttp://oreilly.com/catalog/progcsharp/chapter/ch18.html\nhttp://www.codeguru.com/csharp/.net/net_general/assemblies/article.php/c7009 to see how can used. ",
2010-08-24T13:49:26
Nobody :

Its called an attribute and is used to add metadata to your code.",
2010-08-24T13:45:20
Petr Kozelek :

These are the characters for defining attributes (similar to annotations in Java).",
2010-08-24T13:46:48
Matt Greer :

That is an Attribute. By themselves they do nothing at all, they just decorate code. But code can discover attributes and react to them at runtime.",
2010-08-24T13:44:43
user180326 :

In this case, it is a way to define Attributes on methods and classes. Attributes are like special comments except they get compiled into the dll and can be queried at runtime.",
2010-08-24T13:45:36
yy